/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package de.blitzcoder.collide.util;

import java.io.File;
import java.io.FileNotFoundException;

/**
 *
 * @author blitzcoder
 */
public class FileUtilities {

    private static File ATTRIB = null;

    static {
        if (OS.isWindows()) {
            File windir = new File(System.getenv("windir"));
            if (windir.exists()) {
                File system32 = new File(windir, "system32");
                if (system32.exists()) {
                    File attrib = new File(system32,"ATTRIB.EXE");
                    if (attrib.exists()) {
                        ATTRIB = attrib;
                    } else {
                        throw new Error("Cannot find attrib.exe");
                    }
                } else {
                    throw new Error("Cannot find system32");
                }
            } else {
                throw new Error("Cannot find windir");
            }
        }
    }

    public static void hideFile(File file) {
        if (OS.isWindows()) {
            if (ATTRIB == null) {
                throw new Error("Cannot find attrib.exe");
            } else {
                String[] cmd = {ATTRIB.getAbsolutePath(),"+H",file.getAbsolutePath()};
                try {
                    Process p =Runtime.getRuntime().exec(cmd);
                    p.waitFor();
                } catch (Exception ex) {
                    throw new Error(ex);
                }
            }
        } else {
            throw new Error("Only supported on windows");
        }
    }
}
